unit uStandardNumberFunctions;

interface

uses uNumberFunction, uNumberFunctionFactory;

type

  TFunctionRnd = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionSqr = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionSqrt = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionAbs = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionLog = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionLog2 = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionLn = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionDeg = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionDms = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionSign = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionGamma = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionSin = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionCos = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionTan = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionTg = class(TFunctionTan)
  public
    class function GetName: string; override;
  end;

  TFunctionCotan = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionCotg = class(TFunctionCotan)
  public
    class function GetName: string; override;
  end;

  TFunctionSec = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionCsc = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcSin = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcCos = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcTan = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcTg = class(TFunctionArcTan)
  public
    class function GetName: string; override;
  end;

  TFunctionArcCot = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcCotg = class(TFunctionArcCot)
  public
    class function GetName: string; override;
  end;

  TFunctionSinh = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionCosh = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionTanh = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionTgh = class(TFunctionTanh)
  public
    class function GetName: string; override;
  end;

  TFunctionCoth = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionCotgh = class(TFunctionCoth)
  public
    class function GetName: string; override;
  end;

  TFunctionArcSinh = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcCosh = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcTanh = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcTgh = class(TFunctionArcTanh)
  public
    class function GetName: string; override;
  end;

  TFunctionArcCoth = class(TNumberFunction)
  public
    class function GetName: string; override;
    function Evaluate(AInput: Extended): Extended; override;
  end;

  TFunctionArcCotgh = class(TFunctionArcCoth)
  public
    class function GetName: string; override;
  end;

implementation

uses Math, uFunctions;

{ TFunctionRnd }

function TFunctionRnd.Evaluate(AInput: Extended): Extended;
begin
  Result := Round(AInput);
end;

class function TFunctionRnd.GetName: string;
begin
  Result := 'rnd';
end;

{ TFunctionSqr }

function TFunctionSqr.Evaluate(AInput: Extended): Extended;
begin
  Result := Sqr(AInput);
end;

class function TFunctionSqr.GetName: string;
begin
  Result := 'sqr';
end;

{ TFunctionSqrt }

function TFunctionSqrt.Evaluate(AInput: Extended): Extended;
begin
  Result := Sqrt(AInput);
end;

class function TFunctionSqrt.GetName: string;
begin
  Result := 'sqrt';
end;

{ TFunctionAbs }

function TFunctionAbs.Evaluate(AInput: Extended): Extended;
begin
  Result := Abs(AInput);
end;

class function TFunctionAbs.GetName: string;
begin
  Result := 'abs';
end;

{ TFunctionLog }

function TFunctionLog.Evaluate(AInput: Extended): Extended;
begin
  Result := Log10(AInput);
end;

class function TFunctionLog.GetName: string;
begin
  Result := 'log';
end;

{ TFunctionLog2 }

function TFunctionLog2.Evaluate(AInput: Extended): Extended;
begin
  Result := Log2(AInput);
end;

class function TFunctionLog2.GetName: string;
begin
  Result := 'log2';
end;

{ TFunctionLn }

function TFunctionLn.Evaluate(AInput: Extended): Extended;
begin
  Result := Ln(AInput);
end;

class function TFunctionLn.GetName: string;
begin
  Result := 'ln';
end;

{ TFunctionDeg }

function TFunctionDeg.Evaluate(AInput: Extended): Extended;
begin
  //TODO:
  Result := 0;
end;

class function TFunctionDeg.GetName: string;
begin
  Result := 'deg';
end;

{ TFunctionDms }

function TFunctionDms.Evaluate(AInput: Extended): Extended;
begin
  //TODO:
  Result := 0;
end;

class function TFunctionDms.GetName: string;
begin
  Result := 'dms';
end;

{ TFunctionSign }

function TFunctionSign.Evaluate(AInput: Extended): Extended;
begin
  Result := Sign(AInput);
end;

class function TFunctionSign.GetName: string;
begin
  Result := 'sign';
end;

{ TFunctionGamma }

function TFunctionGamma.Evaluate(AInput: Extended): Extended;
begin
  Result := Gamma(AInput);
end;

class function TFunctionGamma.GetName: string;
begin
  Result := 'gamma';
end;

{ TFunctionSin }

function TFunctionSin.Evaluate(AInput: Extended): Extended;
begin
  Result := Sin(ToRadians(AInput));
end;

class function TFunctionSin.GetName: string;
begin
  Result := 'sin';
end;

{ TFunctionCos }

function TFunctionCos.Evaluate(AInput: Extended): Extended;
begin
  Result := Cos(ToRadians(AInput));
end;

class function TFunctionCos.GetName: string;
begin
  Result := 'cos';
end;

{ TFunctionTan }

function TFunctionTan.Evaluate(AInput: Extended): Extended;
begin
  Result := Tan(ToRadians(AInput));
end;

class function TFunctionTan.GetName: string;
begin
  Result := 'tan';
end;

{ TFunctionTg }

class function TFunctionTg.GetName: string;
begin
  Result := 'tg';
end;

{ TFunctionCotan }

function TFunctionCotan.Evaluate(AInput: Extended): Extended;
begin
  Result := Cotan(ToRadians(AInput));
end;

class function TFunctionCotan.GetName: string;
begin
  Result := 'cotan';
end;

{ TFunctionCotg }

class function TFunctionCotg.GetName: string;
begin
  Result := 'cotg';
end;

{ TFunctionSec }

function TFunctionSec.Evaluate(AInput: Extended): Extended;
begin
  Result := Sec(ToRadians(AInput));
end;

class function TFunctionSec.GetName: string;
begin
  Result := 'sec';
end;

{ TFunctionCsc }

function TFunctionCsc.Evaluate(AInput: Extended): Extended;
begin
  Result := Csc(ToRadians(AInput));
end;

class function TFunctionCsc.GetName: string;
begin
  Result := 'csc';
end;

{ TFunctionArcSin }

function TFunctionArcSin.Evaluate(AInput: Extended): Extended;
begin
  Result := FromRadians(ArcSin(AInput));
end;

class function TFunctionArcSin.GetName: string;
begin
  Result := 'arcsin';
end;

{ TFunctionArcCos }

function TFunctionArcCos.Evaluate(AInput: Extended): Extended;
begin
  Result := FromRadians(ArcCos(AInput));
end;

class function TFunctionArcCos.GetName: string;
begin
  Result := 'arccos';
end;

{ TFunctionArcTan }

function TFunctionArcTan.Evaluate(AInput: Extended): Extended;
begin
  Result := FromRadians(ArcTan(AInput));
end;

class function TFunctionArcTan.GetName: string;
begin
  Result := 'arctan';
end;

{ TFunctionArcTg }

class function TFunctionArcTg.GetName: string;
begin
  Result := 'arctg';
end;

{ TFunctionArcCot }

function TFunctionArcCot.Evaluate(AInput: Extended): Extended;
begin
  Result := FromRadians(ArcCot(AInput));
end;

class function TFunctionArcCot.GetName: string;
begin
  Result := 'arccot';
end;

{ TFunctionArcCotg }

class function TFunctionArcCotg.GetName: string;
begin
  Result := 'arccotg';
end;

{ TFunctionSinh }

function TFunctionSinh.Evaluate(AInput: Extended): Extended;
begin
  Result := Sinh(AInput);
end;

class function TFunctionSinh.GetName: string;
begin
  Result := 'sinh';
end;

{ TFunctionCosh }

function TFunctionCosh.Evaluate(AInput: Extended): Extended;
begin
  Result := Cosh(AInput);
end;

class function TFunctionCosh.GetName: string;
begin
  Result := 'cosh';
end;

{ TFunctionTanh }

function TFunctionTanh.Evaluate(AInput: Extended): Extended;
begin
  Result := Tanh(AInput);
end;

class function TFunctionTanh.GetName: string;
begin
  Result := 'tanh';
end;

{ TFunctionTgh }

class function TFunctionTgh.GetName: string;
begin
  Result := 'tgh';
end;

{ TFunctionCoth }

function TFunctionCoth.Evaluate(AInput: Extended): Extended;
begin
  Result := CotH(AInput);
end;

class function TFunctionCoth.GetName: string;
begin
  Result := 'coth';
end;

{ TFunctionCotgh }

class function TFunctionCotgh.GetName: string;
begin
  Result := 'cotgh';
end;

{ TFunctionArcSinh }

function TFunctionArcSinh.Evaluate(AInput: Extended): Extended;
begin
  Result := ArcSinh(AInput);
end;

class function TFunctionArcSinh.GetName: string;
begin
  Result := 'arcsinh';
end;

{ TFunctionArcCosh }

function TFunctionArcCosh.Evaluate(AInput: Extended): Extended;
begin
  Result := ArcCosh(AInput);
end;

class function TFunctionArcCosh.GetName: string;
begin
  Result := 'arccosh';
end;

{ TFunctionArcTanh }

function TFunctionArcTanh.Evaluate(AInput: Extended): Extended;
begin
  Result := ArcTanh(AInput);
end;

class function TFunctionArcTanh.GetName: string;
begin
  Result := 'arctanh';
end;

{ TFunctionArcTgh }

class function TFunctionArcTgh.GetName: string;
begin
  Result := 'arctgh';
end;

{ TFunctionArcCoth }

function TFunctionArcCoth.Evaluate(AInput: Extended): Extended;
begin
  Result := ArcCotH(AInput);
end;

class function TFunctionArcCoth.GetName: string;
begin
  Result := 'arccoth';
end;

{ TFunctionArcCotgh }

class function TFunctionArcCotgh.GetName: string;
begin
  Result := 'arccotgh';
end;

initialization

  with TNumberFunctionFactory.GetInstance do
  begin
    IncreaseFunctionCapacity(37);

    //TODO: register functions in order from most commonly used to less
    RegisterFunctionClass(TFunctionRnd);
    RegisterFunctionClass(TFunctionSqr);
    RegisterFunctionClass(TFunctionSqrt);
    RegisterFunctionClass(TFunctionAbs);
    RegisterFunctionClass(TFunctionLog);
    RegisterFunctionClass(TFunctionLog2);
    RegisterFunctionClass(TFunctionLn);
    RegisterFunctionClass(TFunctionDeg);
    RegisterFunctionClass(TFunctionDms);
    RegisterFunctionClass(TFunctionSign);
    RegisterFunctionClass(TFunctionGamma);
    RegisterFunctionClass(TFunctionSin);
    RegisterFunctionClass(TFunctionCos);
    RegisterFunctionClass(TFunctionTan);
    RegisterFunctionClass(TFunctionTg);
    RegisterFunctionClass(TFunctionCotan);
    RegisterFunctionClass(TFunctionCotg);
    RegisterFunctionClass(TFunctionSec);
    RegisterFunctionClass(TFunctionCsc);
    RegisterFunctionClass(TFunctionArcSin);
    RegisterFunctionClass(TFunctionArcCos);
    RegisterFunctionClass(TFunctionArcTan);
    RegisterFunctionClass(TFunctionArcTg);
    RegisterFunctionClass(TFunctionArcCot);
    RegisterFunctionClass(TFunctionArcCotg);
    RegisterFunctionClass(TFunctionSinh);
    RegisterFunctionClass(TFunctionCosh);
    RegisterFunctionClass(TFunctionTanh);
    RegisterFunctionClass(TFunctionTgh);
    RegisterFunctionClass(TFunctionCoth);
    RegisterFunctionClass(TFunctionCotgh);
    RegisterFunctionClass(TFunctionArcSinh);
    RegisterFunctionClass(TFunctionArcCosh);
    RegisterFunctionClass(TFunctionArcTanh);
    RegisterFunctionClass(TFunctionArcTgh);
    RegisterFunctionClass(TFunctionArcCoth);
    RegisterFunctionClass(TFunctionArcCotgh);
  end;

end.
